//
//  HMappFrameTabBarController.m
//  miaopai
//
//  Created by 121 on 17/2/28.
//  Copyright © 2017年 121. All rights reserved.
//

#import "HMappFrameTabBarController.h"
#import "HMHomeViewController.h"
#import "HMRemindViewController.h"
#import "HMReportViewController.h"
#import "HMTabBar.h"
#import "HMNavigationController.h"
#import "HMAddViewController.h"

#define kClassKey  @"rootVCClassString"
#define kTitle  @"title"
#define kImgKey @"imageName"
#define kSelImagKey @"selectedImageName"

@interface HMAppFrameTabBarController ()<HMTabBarDelegate>

@end

@implementation HMAppFrameTabBarController

/**
 UITabBar 是由里面的 UITabBarButton组成的 UITabBarButton里面显示什么内容，由对应的
 子控制器的UITabBarItem(tabBarItem) 所决定的。
 */


+ (void)load {
    
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    NSMutableDictionary *dictNormal = [NSMutableDictionary dictionary];
    dictNormal[NSForegroundColorAttributeName] = [UIColor grayColor];
    dictNormal[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    NSMutableDictionary *dictSelected = [NSMutableDictionary dictionary];
    dictSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    dictSelected[NSFontAttributeName] = [UIFont systemFontOfSize:11];

    [item setTitleTextAttributes:dictNormal forState:UIControlStateNormal];
    [item setTitleTextAttributes:dictSelected forState:UIControlStateSelected];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    HMTabBar *tabBar = [[HMTabBar alloc] init];
    tabBar.tabBarDelegate = self;
    [self setValue:tabBar forKey:@"tabBar"];
    
    
}


- (void)initData {
    NSArray *childItemsArray = @[ @{ kClassKey :@"HMHomeViewController",
                                     kTitle :@"首页",
                                     kImgKey :@"icon-首页",
                                     kSelImagKey : @"icon-首页-hover"
                                     },
                                  @{ kClassKey : @"HMRemindViewController",
                                     kTitle :@"提醒",
                                     kImgKey :@"icon-提醒",
                                     kSelImagKey : @"icon-提醒-hover"
                                     },
                                  @{ kClassKey : @"HMReportViewController",
                                     kTitle :@"报表",
                                     kImgKey :@"icon-报表",
                                     kSelImagKey : @"icon-报表-hover"
                                     },
                                  @{ kClassKey :@"HMHomeViewController",
                                     kTitle :@"首页",
                                     kImgKey :@"icon-首页",
                                     kSelImagKey : @"icon-首页-hover"
                                     }
                                  ];
    [childItemsArray enumerateObjectsUsingBlock:^(NSDictionary * dict, NSUInteger idx, BOOL *stop) {
        UIViewController *vc = [NSClassFromString(dict[kClassKey]) new];
        vc.title = dict[kTitle];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
        UITabBarItem *item = nav.tabBarItem;
        item.title = dict[kTitle];
        item.image = [UIImage imageNamed:dict[kImgKey]];
        UIImage *image  = [UIImage imageNamed:dict[kSelImagKey]];
        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = image;
        [self addChildViewController:nav];
    }];
}


- (void)clickAddTabBarEvent:(HMTabBar *)tabBar {
    HMAddViewController *addVc = [[HMAddViewController alloc] init];
    HMNavigationController *navVc = [[HMNavigationController alloc] initWithRootViewController:addVc];
    [self presentViewController:navVc animated:YES completion:nil];
}





@end
